import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/HomeView.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    redirect: "index",
    component: HomeView,
    children: [
      {
        path: "/index",
        name: "index",
        meta: {
          isShow: true,
          title: "首页",
        },
        component: () =>
          import(/* webpackChunkName: "project" */ "../views/MainView.vue"),
      },
      {
        path: "/person",
        name: "person",
        meta: {
          isShow: true,
          title: "人员管理",
        },
        component: () =>
          import(
            /* webpackChunkName: "person" */ "../views/Menu/PersonView.vue"
          ),
      },
      {
        path: "/project",
        name: "project",
        meta: {
          isShow: true,
          title: "项目管理",
        },
        component: () =>
          import(
            /* webpackChunkName: "project" */ "../views/Menu/ProjectView.vue"
          ),
      },
      {
        path: "/projectadd",
        name: "projectadd",
        redirect: "/info",
        component: () => import("../views/Menu/ProjectaddView.vue"),
        meta: { title: "新建项目" },
        children: [
          {
            path: "/info",
            name: "info",
            // meta: { keepAlive: false },
            component: () =>
              import(
                /* webpackChunkName: "about" */ "../views/Menu/step/InfoView.vue"
              ),
          },
          {
            path: "/staffing",
            name: "staffing",
            // meta: { keepAlive: false },
            component: () =>
              import(
                /* webpackChunkName: "about" */ "../views/Menu/step/StaffingView.vue"
              ),
          },
          {
            path: "/process",
            name: "process",
            // meta: { keepAlive: true },
            component: () =>
              import(
                /* webpackChunkName: "about" */ "../views/Menu/step/ProcessView.vue"
              ),
          },
        ],
      },
      {
        path: "/check",
        name: "check",
        // meta: { keepAlive: true },
        component: () =>
          import(
            /* webpackChunkName: "about" */ "../views/Menu/step/CheckView.vue"
          ),
      },
      {
        path: "/dict",
        name: "dict",
        meta: {
          //原信息
          isShow: true,
          title: "字典维护",
        },
        component: () =>
          import(/* webpackChunkName: "dict" */ "../views/Menu/DictView.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/LoginView.vue"),
  },
  {
    path: "/register",
    name: "register",
    component: () =>
      import(/* webpackChunkName: "register" */ "../views/RegisterView.vue"),
  },
];

const router = createRouter({
  history: createWebHistory("/team2"),
  routes,
});
//全局路由守卫
router.beforeEach((to,from,next)=>{
  const token:string | null=localStorage.getItem('token')
  if(!token && to.path!=='/login'){
    next('/login')
  }else{
    next()
  }
})
export default router;
